//
//  anpaiview.m
//  PASystem
//
//  Created by michael on 16/9/28.
//  Copyright © 2016年 czd. All rights reserved.
//

#import "anpaiview.h"

@implementation anpaiview
- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {


          }
    return self;
}

- (void)setId:(NSString *)id{
_id = id;


[self request];
}
- (void)initview{


_tab = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.width, self.height) style:1];
_tab.backgroundColor = [UIColor whiteColor];
_tab.dataSource = self;
_tab.delegate = self;
[self addSubview:_tab];


}
- (void)request{
NSString * userId = [[NSUserDefaults standardUserDefaults]objectForKey:@"userId"];
    NSString * pwdId = [[NSUserDefaults standardUserDefaults]objectForKey:@"pwdId"];
    NSString * userHumber = [[NSUserDefaults standardUserDefaults]objectForKey:@"userHumber"];
    
//1
      NSString *json1  = [NSString stringWithFormat:@"{'action': ysapMch,'service': DXMService, 'userName':'%@','password':'%@', 'vaueJson':'{userid :%@,id:%@}'}",userId,pwdId,userHumber,self.id];
    
    NSArray * array1 = @[@{@"arg0":json1}];
[HttpTools requestWithURL:BaseURL arrays:array1 method:Basemethod success:^(id JSON) {
     NSArray *array = JSON[@"reason"];
     NSDictionary *dic = [array firstObject];
        NSDictionary *dict = dic[@"attrs"];
       _dic1 = dict;
    [self do2];
    } failure:^(NSError *error) {
        
    }];

    

}
- (void)do2{
NSString * userId = [[NSUserDefaults standardUserDefaults]objectForKey:@"userId"];
    NSString * pwdId = [[NSUserDefaults standardUserDefaults]objectForKey:@"pwdId"];
    NSString * userHumber = [[NSUserDefaults standardUserDefaults]objectForKey:@"userHumber"];
 NSString *json2  = [NSString stringWithFormat:@"{'action': hqapMch,'service': DXMService, 'userName':'%@','password':'%@', 'vaueJson':'{userid :%@,id:%@}'}",userId,pwdId,userHumber,self.id];
    
    NSArray * array2 = @[@{@"arg0":json2}];
[HttpTools requestWithURL:BaseURL arrays:array2 method:Basemethod success:^(id JSON) {
     NSArray *array = JSON[@"reason"];
     NSDictionary *dic = [array firstObject];
        NSDictionary *dict = dic[@"attrs"];
       _dic2 = dict;
        [self do3];

    } failure:^(NSError *error) {
        
    }];



}
- (void)do3{
NSString * userId = [[NSUserDefaults standardUserDefaults]objectForKey:@"userId"];
    NSString * pwdId = [[NSUserDefaults standardUserDefaults]objectForKey:@"pwdId"];
    NSString * userHumber = [[NSUserDefaults standardUserDefaults]objectForKey:@"userHumber"];

      NSString *json3  = [NSString stringWithFormat:@"{'action': zpysMch,'service': DXMService, 'userName':'%@','password':'%@', 'vaueJson':'{userid :%@,id:%@}'}",userId,pwdId,userHumber,self.id];
    
    NSArray * array3 = @[@{@"arg0":json3}];
[HttpTools requestWithURL:BaseURL arrays:array3 method:Basemethod success:^(id JSON) {
     NSDictionary *dic0 = JSON[@"reason"];
        NSDictionary *dict = dic0[@"attrs"];
       _dic3 = dict;
        [self do4];

    } failure:^(NSError *error) {
        
    }];



}
- (void)do4{
NSString * userId = [[NSUserDefaults standardUserDefaults]objectForKey:@"userId"];
    NSString * pwdId = [[NSUserDefaults standardUserDefaults]objectForKey:@"pwdId"];
    NSString * userHumber = [[NSUserDefaults standardUserDefaults]objectForKey:@"userHumber"];
     NSString *json4  = [NSString stringWithFormat:@"{'action': hyzlMch,'service': DXMService, 'userName':'%@','password':'%@', 'vaueJson':'{userid :%@,id:%@}'}",userId,pwdId,userHumber,self.id];
    
    NSArray * array4 = @[@{@"arg0":json4}];
[HttpTools requestWithURL:BaseURL arrays:array4 method:Basemethod success:^(id JSON) {
     NSDictionary *dic0 = JSON[@"reason"];
        NSDictionary *dict = dic0[@"attrs"];
       _dic4 = dict;
        [self do5];

    } failure:^(NSError *error) {
        
    }];



}
- (void)do5{

NSString * userId = [[NSUserDefaults standardUserDefaults]objectForKey:@"userId"];
    NSString * pwdId = [[NSUserDefaults standardUserDefaults]objectForKey:@"pwdId"];
    NSString * userHumber = [[NSUserDefaults standardUserDefaults]objectForKey:@"userHumber"];

      NSString *json5  = [NSString stringWithFormat:@"{'action': tdypMch,'service': DXMService, 'userName':'%@','password':'%@', 'vaueJson':'{userid :%@,id:%@}'}",userId,pwdId,userHumber,self.id];
    
    NSArray * array5 = @[@{@"arg0":json5}];
[HttpTools requestWithURL:BaseURL arrays:array5 method:Basemethod success:^(id JSON) {
     NSDictionary *dic0 = JSON[@"reason"];
        NSDictionary *dict = dic0[@"attrs"];
       _dic5 = dict;
//    [_tab reloadData];
 [self initview];
    } failure:^(NSError *error) {
        
    }];



}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 5;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
                return 1;
 }
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.section == 0) {
    static NSString *CellIdentifier = @"Cell0";

    anpaiTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  if (cell==nil) {  
        cell=[[anpaiTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }
    cell.dict = _dic1;
    return cell;

}
else if (indexPath.section == 1) {
    static NSString *CellIdentifier = @"Cell1";

    anpaiTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  if (cell==nil) {  
        cell=[[anpaiTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }
    cell.dict = _dic2;
    return cell;

}
else if  (indexPath.section == 2) {
    
     UITableViewCell* cell = [[UITableViewCell alloc]init];
       NSString *string = _dic3[@"SITUATION"];

     NSString *result = [string stringByReplacingOccurrencesOfString:@"&quot;" withString:@"\""];

result = [result stringByReplacingOccurrencesOfString:@"&lt;" withString:@"<"];
result = [result stringByReplacingOccurrencesOfString:@"&gt;" withString:@">"];


 UIWebView *web= [[UIWebView alloc]initWithFrame:CGRectMake(0,0,self.width,100)];
 web.delegate = self;
 [web loadHTMLString:result baseURL:nil];
 web.backgroundColor = [UIColor whiteColor];
       [cell.contentView addSubview:web];
    return cell;

}
else if  (indexPath.section == 3) {
    static NSString *CellIdentifier = @"Cell3";

    anpaiTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  if (cell==nil) {  
        cell=[[anpaiTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }
    cell.dict = _dic4;
    return cell;

}
else{
    static NSString *CellIdentifier = @"Cell4";

    anpaiTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  if (cell==nil) {  
        cell=[[anpaiTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }
    cell.dict = _dic5;
    return cell;

}



}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if(indexPath.section ==2){
return 200;

}else{

return 120;
}

}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
if (section == 0){
 UIView *bgv = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth - 20, 30)];
    bgv.backgroundColor = [UIColor whiteColor];
    
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(20, 0,KScreenWidth - 20,30)];
    label.text = @"资金预算和安排情况";
    
    label.textColor = [UIColor blueColor];
    
    label.font = [UIFont systemFontOfSize:15];
    
    [bgv addSubview:label];
    
    UIView *vi = [[UIView alloc] initWithFrame:CGRectMake(10, 10, 4, 10)];
    vi.backgroundColor = [UIColor blueColor];
    
    [bgv addSubview:vi];
return bgv;

}
if (section == 1){
 UIView *bgv = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth - 20, 30)];
    bgv.backgroundColor = [UIColor whiteColor];
    
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(20, 0,KScreenWidth - 20,30)];
    label.text = @"互签安排";
    
    label.textColor = [UIColor blueColor];
    
    label.font = [UIFont systemFontOfSize:15];
    
    [bgv addSubview:label];
    
    UIView *vi = [[UIView alloc] initWithFrame:CGRectMake(10, 10, 4, 10)];
    vi.backgroundColor = [UIColor blueColor];
    
    [bgv addSubview:vi];
return bgv;

}
if (section == 2){
 UIView *bgv = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth - 20, 30)];
    bgv.backgroundColor = [UIColor whiteColor];
    
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(20, 0,KScreenWidth - 20,30)];
    label.text = @"展品运输";
    
    label.textColor = [UIColor blueColor];
    
    label.font = [UIFont systemFontOfSize:15];
    
    [bgv addSubview:label];
    
    UIView *vi = [[UIView alloc] initWithFrame:CGRectMake(10, 10, 4, 10)];
    vi.backgroundColor = [UIColor blueColor];
    
    [bgv addSubview:vi];
return bgv;

}
if (section == 3){
 UIView *bgv = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth - 20, 30)];
    bgv.backgroundColor = [UIColor whiteColor];
    
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(20, 0,KScreenWidth - 20,30)];
    label.text = @"编译各种会议配套资料";
    
    label.textColor = [UIColor blueColor];
    
    label.font = [UIFont systemFontOfSize:15];
    
    [bgv addSubview:label];
    
    UIView *vi = [[UIView alloc] initWithFrame:CGRectMake(10, 10, 4, 10)];
    vi.backgroundColor = [UIColor blueColor];
    
    [bgv addSubview:vi];
return bgv;

}
else{
 UIView *bgv = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth - 20, 30)];
    bgv.backgroundColor = [UIColor whiteColor];
    
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(20, 0,KScreenWidth - 20,30)];
    label.text = @"购置团队用品";
    
    label.textColor = [UIColor blueColor];
    
    label.font = [UIFont systemFontOfSize:15];
    
    [bgv addSubview:label];
    
    UIView *vi = [[UIView alloc] initWithFrame:CGRectMake(10, 10, 4, 10)];
    vi.backgroundColor = [UIColor blueColor];
    
    [bgv addSubview:vi];
return bgv;

}
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
 
        return 30;;
    }

@end
